<template>
  <el-dialog :id="target" :close-on-click-modal="closeonclickmodal" width="400px" :title="dialoginfo.title"
             @open="listenopen()"
             @close="close" :visible="dialoginfo.show">
    <el-form :model="dialoginfo.data" ref="dialoginfo" label-position="left">
      <el-row>
        <el-col :span="24">
          <el-form-item :rules="[{ required: true, message: '不能为空'}]"
                        prop="keyName" label="键" :label-width="formLabelWidth">
            <el-input disabled type="text" v-model.trim="dialoginfo.data.keyName" auto-complete="off" clearable></el-input>
          </el-form-item>
          <el-form-item :rules="[{ required: true, message: '不能为空'}]"
                        prop="descript" label="配置描述" :label-width="formLabelWidth">
            <el-input type="textarea" rows="4" v-model.trim="dialoginfo.data.descript" auto-complete="off" clearable></el-input>
          </el-form-item>
          <el-form-item :rules="[{ required: true, message: '不能为空'}]"
                        prop="keyValue" label="值" :label-width="formLabelWidth">
            <el-input type="text"  v-model.trim="dialoginfo.data.keyValue" auto-complete="off" clearable></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-form-item style="text-align: right">
          <el-button size="mini" @click="dialoginfo.show = false">取 消</el-button>
          <el-button size="mini" type="primary" @click="toAdd('dialoginfo')">保 存</el-button>
        </el-form-item>
      </el-row>
    </el-form>
  </el-dialog>
</template>
<script>
  export default {
    inject: ["reload"],
    data() {
      return {
        types:[{opt:0,alias:'启用'},{opt:1,alias:'禁用'}],
        target: "userBaseInfoEdit",
        dialogVisible: false,
        isajax: false,
        closeonclickmodal: true,
        formLabelWidth: '80px'
      }
    },
    props: ['dialoginfo'],
    methods: {
      listenopen() {
        if (this.isadd && this.$refs['dialoginfo'] != null) {
          this.$refs['dialoginfo'].resetFields();
        }
      },
      close() {
        this.$emit('changedialogshow')
      },
      lockClick(){
        if (this.dialoginfo.data.state == 0) {
          this.dialoginfo.data.state = 1;
        } else {
          this.dialoginfo.data.state = 0;
        }
      },
      toAdd(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            this.$store.commit("saveLoadingMap", {"target": this.dialoginfo.url,id:this.target});
            this.proAPI.postJson(this.dialoginfo.url, this.dialoginfo.data).then((res) => {
              this.$message.success({
                "message": res.message
              })
              setTimeout(()=>{
                this.reload();
              },1000)
            });
          } else {
            return false;
          }
        });
      }
    },
    updated() {
    },
    mounted() {
    }
  };
</script>
<style scoped>
</style>
